package com.sevenGroup.pawnshop.handle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sevenGroup.pawnshop.Utils.CopyProperties;
import com.sevenGroup.pawnshop.Utils.Result;
import com.sevenGroup.pawnshop.controller.info.AccountInfo;
import com.sevenGroup.pawnshop.dao.UsersDao;
import com.sevenGroup.pawnshop.model.Account;
import com.sevenGroup.pawnshop.model.Users;
import org.apache.catalina.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;

public class successHandler implements AuthenticationSuccessHandler {

    ObjectMapper om=new ObjectMapper();

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest,
                                        HttpServletResponse httpServletResponse,
                                        Authentication authentication) throws IOException, ServletException {
        Account account = (Account) (authentication.getPrincipal());
        Result success = Result.success(CopyProperties.copyOne(account, AccountInfo.class));
        success.setMessage("登陆成功");

        httpServletResponse.setCharacterEncoding("utf-8");
        httpServletResponse.setContentType("application/json;charset=utf-8");
        String string = om.writeValueAsString(success);
        httpServletResponse.getWriter().write(string);
        httpServletResponse.getWriter().flush();
    }
}
